/**
 * create by young (young2f@outlook.com) on 2020/9/16
 * 创建字典
 */


'use strict';
import React from 'react';
import {AutoComplete, Button, DatePicker, Form, Input, InputNumber, notification} from 'antd';

import FormBase from '../../components/Base/FormBase';

import moment from 'moment';
import 'moment/locale/zh-cn';

import {FormField, FormLayout, ModalFooter} from "antd-extra";

moment.locale('zh-cn');

@Form.create()
export default class ModalCreateDict extends FormBase {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {

  }

  renderFoot = () => {
    const {foot, value, modalRef, type, form, callback} = this.props;

    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button type="primary" onClick={() => {
            const {modalRef} = this.props;
            form.validateFields((err, values) => {
              if (err) {
                const {code} = err;
                const {errors} = code;
                errors.forEach(item => {
                  notification.error(item);
                });
                return;
              }
              values.type = type;
              callback(values)
              modalRef.close();
            })
          }}>确定</Button>

          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };

  getMaterialInfo() {
    const {form, cols = 1,} = this.props;
    return <FormLayout form={form} cols={cols}>

      <FormField
        label={'名称'}
        name={'name'}
        required={true}
      >
        <Input style={{width: '100%'}}></Input>
      </FormField>

    </FormLayout>
  }

  render() {
    const {style = {}} = this.props;
    return (
      <div style={{...style}}>
        {this.getMaterialInfo()}
        {this.renderFoot()}
      </div>

    );
  }
}

